package hcs.model;


import hcs.HouseController;
import hcs.interfaces.PriorityObservable;

import java.util.Observer;

import stubs.IPhysicalBoiler;
import stubs.IPhysicalEnvironment;
import stubs.IPhysicalRoom;

/**
 * A Singleton class which notifies its {@link Observer}s
 * when {@link #tic} is called
 */
public class Clock extends PriorityObservable {
	private static Clock instance;
	
	private Clock() {
		
	}
	
	/**
	 * @return the {@link Clock} instance
	 */
	public static synchronized Clock getInstance() {
		if(instance == null)
			instance = new Clock();
		return instance;
	}
	
	/**
	 *  Notify registered {@link Observer}s 
	 */
	public void tic() {
		this.setChanged();
		this.notifyObservers();
	}

	@Override
	public int getPriority(Object o) {
		int priority;
		if (o instanceof HouseController) {
			priority = 0;
		} 
		else  if (o instanceof Boiler) {
			priority = -1;
		}
    	else if (o instanceof Environment) {
			priority = -2;
		} 
    	else if (o instanceof IPhysicalRoom) {
			priority = -3;
		}
    	else if (o instanceof IPhysicalBoiler) {
    		priority = -4;
    	}
    	else if (o instanceof IPhysicalEnvironment) {
			priority = -5;
		} 
    	else {
			priority = 1;
		}
		return priority;
	}
}
